package com.jzr.medical.db1.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.jzr.medical.common.LayMapper;
import com.jzr.medical.db1.model.TRole;
import com.jzr.medical.db1.vo.RoleDeptVo;
import com.jzr.medical.db1.vo.RoleMenuTreeVo;
import com.jzr.medical.db1.vo.RoleUserVo;
import com.jzr.medical.db1.vo.RoleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author henry
 * @since 2019-07-22
 */
public interface TRoleMapper extends LayMapper<TRole,RoleVo,Integer> {
    List<Integer> getIdList(@Param(Constants.WRAPPER) Wrapper wrapper);
    @Select("select id,name from t_role order by sort")
    List<Map<String,Object>> codeList();

    @Select("select m.id,m.parent_id, m.`name`,rm.role_id,rm.role_id is not null as checked from t_menu m left join (select * from t_role_menu_ref where role_id=#{roleId}) rm on m.id = rm.menu_id order by m.sort")
    List<RoleMenuTreeVo> getRoleMenuTree(Integer roleId);

    @Select("select u.id,u.user_code,u.user_name,ur.role_id from t_user u left join (select * from t_user_role_ref where role_id=#{roleId}) ur on u.id = ur.user_id where u.status=1")
    List<RoleUserVo> getUserList(Integer roleId);

    @Select("select d.id,d.code,d.name,rd.role_id from t_dept d left join (select * from t_role_dept_ref where role_id=#{roleId}) rd on d.id = rd.dept_id where d.status=1")
    List<RoleDeptVo> getDeptList(Integer roleId);

}

